package net.begincode.service.project.impl;

import java.util.List;

import utils.CacheUtils;
import config.DbTemplate;
import net.begincode.bean.BcProject;
import net.begincode.bean.ProjectStage;
import net.begincode.service.project.ProjectService;

public class ProjectServiceImpl implements ProjectService {

	private ProjectServiceImpl() {
	}

	private static ProjectServiceImpl instance = null;

	public static ProjectServiceImpl getInstance() {
		if (instance == null) {
			synchronized (ProjectServiceImpl.class) {
				if (instance == null) {
					instance = new ProjectServiceImpl();
				}
			}
		}
		return instance;
	}
	@Override
	public List<BcProject> selProject() {
		
		String selSql = " select * from bc_project where check_flag = '1' ";
		return DbTemplate.queryForListNoParam(selSql, BcProject.class);
	}
	@Override
	public BcProject selProById(String id) {
		
		String selSql = " select * from bc_project where bc_project_id = ? ";
		return DbTemplate.queryForObject(selSql, new Object[]{id}, BcProject.class);
	}
	@Override
	public BcProject selProByIdCache(String id) {
		Object dbEle = CacheUtils.getEleByNameAndKey(CacheUtils.PROJ_CACHE, "project"+ id);
		if(dbEle != null){
			return (BcProject)dbEle;
		}else{
			String selSql = " select * from bc_project where bc_project_id = ? ";
			BcProject ccs = DbTemplate.queryForObject(selSql, new Object[]{id}, BcProject.class);
			CacheUtils.addEleByParam(CacheUtils.PROJ_CACHE, "project"+ id, ccs);
			return ccs;
		}
	}

}
